package cc.lj.internal.payment.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.payment.domain.settlement.repository.ICouponsCapLogRepository;
import cc.lj.internal.payment.infrastructure.dao.ICouponsCapLogMapper;
import cc.lj.internal.payment.infrastructure.exception.PaymentExceptionEnum;
import cc.lj.internal.payment.infrastructure.po.CouponsCapLogPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 电子券封顶额计算日志表　mysql仓储实现
 * @author liangxifeng
 * @date 2022-10-24
 */
@Repository("couponsCapLogMysqlRespository")
public class CouponsCapLogMysqlRespository implements ICouponsCapLogRepository,BasePageHelper<CouponsCapLogPO> {
    @Autowired
    private ICouponsCapLogMapper mapper;
    @Override
    public List<CouponsCapLogPO> list(CouponsCapLogPO entityPO) {
        QueryWrapper<CouponsCapLogPO> wrapper = new QueryWrapper<>(entityPO);
        List<CouponsCapLogPO> entitys = mapper.selectList(wrapper);
        return entitys;
    }

    @Override
    public PageInfo<CouponsCapLogPO> selectPage(PageParam pageParam) {
        return this.page(pageParam);
    }


    @Override
    public List<CouponsCapLogPO> getList(CouponsCapLogPO logPO) {
        return this.list(logPO);
    }

    @Override
    public Integer insert(CouponsCapLogPO logPO) {
        Integer rows = mapper.insert(logPO);
        if(rows != 1) {
            throw new ServiceException(PaymentExceptionEnum.INSERT_COUPONS_CAP_LOG_FAILED);
        }
        return logPO.getId();
    }

    @Override
    public CouponsCapLogPO getById(Integer id) {
        return mapper.selectById(id);
    }

}
